export function throttle(fn: (...args: any[]) => any, delay: number) {
  let timer: ReturnType<typeof setTimeout> | null = null
  let last: number = 0
  return function <T>(this: (...args: any[]) => any, ...args: Array<T>) {
    const now = +new Date()
    if (last && now < last + delay) {
      clearTimeout(timer)
      timer = setTimeout(() => {
        last = now
        fn.apply(this, args)
      }, delay)
    } else {
      last = now
      fn.apply(this, args)
    }
  }
}
